//package com.example.yk2021xm04.config.security;
//
//import com.example.yk2021xm04.pojo.User;
//import com.example.yk2021xm04.service.IRbacService;
//import com.example.yk2021xm04.service.IUserService;
//import com.example.yk2021xm04.utils.AssertUtil;
//import com.example.yk2021xm04.utils.StringUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.dao.EmptyResultDataAccessException;
//import org.springframework.security.core.authority.AuthorityUtils;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.List;
//
///**
// * @author ZengQi
// * @description: TODO
// * @date 2021/12/11 0011 0:11
// */
//@Component
//public class UserSecurityService implements UserDetailsService {
//    //日志打印
//    private static Logger logger = LoggerFactory.getLogger(UserSecurityService.class);
//
//    @Resource
//    private IUserService userService;
//
//    @Resource
//    private IRbacService rbacService;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) {
//        logger.info("用户名："+username);
//        //判断用户名是否为空
//        AssertUtil.isTrue(StringUtil.isEmpty(username),"用户名不能为空!");
//
//        User user = this.userService.findUserByUserName(username);
//        //能不能找到用户
//        AssertUtil.isTrue(null == user,"该用户记录不存在或已注销!");
//
//        AssertUtil.isTrue(user.getActiveStatus() == 0, "该用户未激活");
//
//        /**
//         * 1. 查询用户分配的角色
//         * 2. 查询用户扮演角色的权限记录
//         */
//        List<String> roleNames = rbacService.findRoleByUserName(username);
//
//        user.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList(String.join(",",roleNames)));
//
//        return user;
//    }
//}
